import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ItemData } from "../../../resource/info/ItemData";
import { MountUtil } from "../../../scene/mount/MountUtil";
import { MountConfig } from "../../../resource/MountConfig";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
type int = number;
//class MountStartsDataPart
    
    export  class MountStartsDataPart /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initView();
            return;
        }

        /* internal  */initView(): void
        {
            ObjCreate.createBg(0, 0, 167, 300, this);
            ObjCreate.createBg(1, 1, 125, 25, this, ImagesConst.TileBg);
            ObjCreate.createBg(1, 147, 125, 25, this, ImagesConst.TileBg);
            this._sCurDataBm = ObjCreate.createBitmap("", 5, 3, this);
            this._sAllDataBm = ObjCreate.createBitmap("", 5, 149, this);
            ObjCreate.createBg(84, 19, 170, 3, this, ImagesConst.Line).rotation = 90;
            ObjCreate.createBg(84, 173, 170, 3, this, ImagesConst.Line).rotation = 90;
            ObjCreate.createBg(3, 144, 150, 3, this, ImagesConst.SplitLine);
            this._curSp = new Object /* flash.display.Sprite */();
            this._curSp.x = 6;
            this._curSp.y = 28;
            this._curSp.name = "curSp";
            addChild(this._curSp);
            this._allSp = new Object /* flash.display.Sprite */();
            this._allSp.x = 6;
            this._allSp.y = 177;
            this._allSp.name = "allSp";
            addChild(this._allSp);
            LoaderHelp.addResCallBack(ResFileConst.mountStarts, this.onLoadBmResource);
            return;
        }

        /* internal  */onLoadBmResource(): void
        {
            this._sCurDataBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.mountStartsCurBm);
            this._sAllDataBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.mountStartsAllBm);
            return;
        }

        public updateInfo(arg1: ItemData): void
        {
            this._mountIdata = arg1;
            if (this._mountIdata.itemExInfo.m_haSt == "0" || this._mountIdata.itemExInfo.m_haSt == "") 
            {
                this.cleanCurSp();
                this.cleanAllSp();
            }
            return;
        }

        public update(arg1: int): void
        {
            var loc1=0;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            this._startsLv = arg1 + 1;
            this.clean();
            if (!this._mountIdata) 
            {
                return;
            }
            if (this._mountIdata.itemExInfo.mount_rein >= 2 && this._mountIdata.itemExInfo.m_haSt == "1") 
            {
                loc1 = this._mountIdata.itemExInfo.m_stTa[arg1];
                loc2 = this._startsLv + "_" + loc1;
                loc3 = MountUtil.instance.getCurStartsData(this._startsLv, this._mountIdata.itemExInfo.m_stLv[arg1], MountConfig.instance.getLvColor2Factor(loc2));
                this.sortText(loc3, this._curSp);
                loc4 = MountUtil.instance.getAllStartsData(this._mountIdata.itemExInfo.m_stLv, this._mountIdata.itemExInfo.m_stTa);
                this.sortText(loc4, this._allSp);
            }
            return;
        }

        /* internal  */sortText(arg1: Array<any>, arg2: Object /* flash.display.DisplayObjectContainer */): void
        {
            var loc1=null;
            var loc4=0;
            var loc5=0;
            arg1.sortOn("key");
            var loc2=arg1.length;
            var loc3=Math.ceil(loc2 / 2);
            if (arg2.name != "curSp") 
            {
                loc5 = 169;
            }
            else 
            {
                loc5 = 20;
            }
            var loc6=0;
            while (loc6 < loc2) 
            {
                loc4 = Math.floor(loc6 % loc3) * 25;
                loc1 = ObjCreate.createTextField("", Math.floor(loc6 / loc3) * 82, loc4, 70, loc5, arg2);
                loc1.htmlText = HTMLUtil.addColor(arg1[loc6].name + "：", GlobalStyle.color1) + HTMLUtil.addColor(arg1[loc6].value, GlobalStyle.color2);
                ++loc6;
            }
            return;
        }

        public clean(): void
        {
            this.cleanCurSp();
            this.cleanAllSp();
            return;
        }

        public cleanCurSp(): void
        {
            while (this._curSp.numChildren > 0) 
            {
                this._curSp.removeChildAt(0);
            }
            return;
        }

        public cleanAllSp(): void
        {
            while (this._allSp.numChildren > 0) 
            {
                this._allSp.removeChildAt(0);
            }
            return;
        }

        /* internal */ /* var */_sCurDataBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sAllDataBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_curSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_allSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_mountIdata: ItemData;

        /* internal */ /* var */_startsLv: int;
    }
